﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;

namespace SageKing.OpenIddict.UI.Identity.Api;

public class LoginViewModel
{

    [Required]
    public string UserName { get; set; }
    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    public string Password { get; set; }

    public bool IsPersistent { get; set; } = true;
    public bool LockoutOnFailure { get; set; } = true;

}

public class SignInResultVM
{
    public bool Succeeded { get; set; }
    public bool Failed { get; set; }
    public bool IsLockedOut { get; set; }
    public bool IsNotAllowed { get; set; }
    public bool RequiresTwoFactor { get; set; }

    public Dictionary<string, string> User { get; set; }
    public string Token { get; set; }

    public static SignInResultVM GetVM(SignInResult signInResult)
    {
        return new SignInResultVM
        {
            Succeeded = signInResult.Succeeded,
            Failed = signInResult.IsNotAllowed,
            IsLockedOut = signInResult.IsLockedOut,
            IsNotAllowed = signInResult.IsNotAllowed,
            RequiresTwoFactor = signInResult.RequiresTwoFactor
        };
    }
}